package com.song.NacosServiceRegistry;

import com.song.transport.RPCRequest;

import java.util.List;

/**
 * Dubbo 的 ConsistentHashLoadBalance 即一致性Hash负载均衡策略
 *
 * 此处为简单的轮询负载均衡
 */
public class RoundRobinLoadBalancer implements LoadBalancer{
    private int index = 0;

    @Override
    public <T> T select(List<T> t, RPCRequest rpcRequest) {
        if(index >= t.size()) {
            index %= t.size();
        }
        return t.get(index++);
    }
}
